package com.littlec.sdk.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;

import android.util.Log;

import com.littlec.sdk.CMChatConfig;

public class MyLogger {
	private static final String LOG_TAG = "LITTLEC-IM-SDK";
	private static Hashtable<String, MyLogger> sLoggerTable = new Hashtable();
	private String mClassName;

	public static MyLogger getLogger(String className) {
		MyLogger classLogger = (MyLogger) sLoggerTable.get(className);
		if (classLogger == null) {
			classLogger = new MyLogger(className);
			sLoggerTable.put(className, classLogger);
		}
		return classLogger;
	}

	private MyLogger(String name) {
		this.mClassName = name;
	}

	public void v(String log) {
		if (CMChatConfig.APPConfig.isDebuggerEnabled()) {
			Log.v("LITTLEC-IM-SDK", "{Thread:"
					+ Thread.currentThread().getName() + "}" + "["
					+ this.mClassName + ":] " + log);
			if (CMChatConfig.APPConfig.isSystemoutEnabled()) {
				String time = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")
						.format(new Date());
				System.out.println(time + " {Thread:"
						+ Thread.currentThread().getName() + "}" + "["
						+ this.mClassName + ":] " + log);
			}
		}
	}

	public void d(String log) {
		if (CMChatConfig.APPConfig.isDebuggerEnabled()) {
			Log.d("LITTLEC-IM-SDK", "{Thread:"
					+ Thread.currentThread().getName() + "}" + "["
					+ this.mClassName + ":] " + log);
			if (CMChatConfig.APPConfig.isSystemoutEnabled()) {
				String time = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")
						.format(new Date());
				System.out.println(time + "{Thread:"
						+ Thread.currentThread().getName() + "}" + "["
						+ this.mClassName + ":] " + log);
			}
		}
	}

	public void i(String log) {
		if (CMChatConfig.APPConfig.isDebuggerEnabled()) {
			Log.i("LITTLEC-IM-SDK", "{Thread:"
					+ Thread.currentThread().getName() + "}" + "["
					+ this.mClassName + ":] " + log);
			if (CMChatConfig.APPConfig.isSystemoutEnabled()) {
				String time = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")
						.format(new Date());
				System.out.println(time + "{Thread:"
						+ Thread.currentThread().getName() + "}" + "["
						+ this.mClassName + ":] " + log);
			}
		}
	}

	public void i(String log, Throwable tr) {
		if (CMChatConfig.APPConfig.isDebuggerEnabled())
			Log.i("LITTLEC-IM-SDK",
					"{Thread:" + Thread.currentThread().getName() + "}" + "["
							+ this.mClassName + ":] " + log + "\n"
							+ Log.getStackTraceString(tr));
	}

	public void w(String log) {
		if (CMChatConfig.APPConfig.isDebuggerEnabled()) {
			Log.w("LITTLEC-IM-SDK", "{Thread:"
					+ Thread.currentThread().getName() + "}" + "["
					+ this.mClassName + ":] " + log);
			if (CMChatConfig.APPConfig.isSystemoutEnabled()) {
				String time = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")
						.format(new Date());
				System.out.println(time + "{Thread:"
						+ Thread.currentThread().getName() + "}" + "["
						+ this.mClassName + ":] " + log);
			}
		}
	}

	public void w(String log, Throwable tr) {
		if (CMChatConfig.APPConfig.isDebuggerEnabled())
			Log.w("LITTLEC-IM-SDK",
					"{Thread:" + Thread.currentThread().getName() + "}" + "["
							+ this.mClassName + ":] " + log + "\n"
							+ Log.getStackTraceString(tr));
	}

	public void e(String log) {
		if (CMChatConfig.APPConfig.isDebuggerEnabled()) {
			Log.e("LITTLEC-IM-SDK", "{Thread:"
					+ Thread.currentThread().getName() + "}" + "["
					+ this.mClassName + ":] " + log);
			if (CMChatConfig.APPConfig.isSystemoutEnabled()) {
				String time = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")
						.format(new Date());
				System.out.println(time + "{Thread:"
						+ Thread.currentThread().getName() + "}" + "["
						+ this.mClassName + ":] " + log);
			}
		}
	}

	public void e(String log, Throwable tr) {
		if (CMChatConfig.APPConfig.isDebuggerEnabled()) {
			Log.e("LITTLEC-IM-SDK",
					"{Thread:" + Thread.currentThread().getName() + "}" + "["
							+ this.mClassName + ":] " + log + "\n"
							+ Log.getStackTraceString(tr));
			if (CMChatConfig.APPConfig.isSystemoutEnabled())
				System.out.println("{Thread:"
						+ Thread.currentThread().getName() + "}" + "["
						+ this.mClassName + ":] " + log);
		}
	}
}
